__author__ = 'Daan'

class stub_bases(object):
    """
    Stubs the __class__.__bases__ from class toStub
    """

    def __init__(self, toStub, extraType):
        self._extraType = extraType
        self._toStub = toStub
        self._old = None

    def __enter__(self):
        from copy import deepcopy
        self._old = deepcopy(self._toStub.__bases__)

        self._toStub.__bases__ = (self._extraType, ) + self._toStub.__bases__
        return self

    #noinspection PyUnusedLocal
    def __exit__(self, exc_type, exc_val, exc_tb):
        self._toStub.__bases__ = self._old